home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / VOXRAY.ZIP / SOUND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-06  |  2.8 KB  |  145 lines

  1. #include "ray.h"
  2.  
  3. #ifdef OS_DOS
  4. #include "modplay.h"
  5. #endif
  6.  
  7. #include "soundint.h"  
  8. #include "cmem.h"
  9. #include <process.h>
  10. #include <stddef.h>
  11. #include <stdio.h>
  12.  
  13. #define DEF_WAV "fhorse.wav"
  14. #define DEFAULT_IO 0x220
  15. #define DEFAULT_IRQ 5
  16. #define DEFAULT_DMA 1
  17. #define KHZ_22 22222
  18. #define DEF_CHANS 8
  19. #define DEF_VOICE 7
  20. #define SC_FILE "sound.cfg"
  21. #define START_CHANNEL 4
  22. #define MAX_CHANNEL 8
  23. #define MAX_SAMPLES 20
  24.  
  25. UCHAR cur_channel=START_CHANNEL;
  26. USHORT the_port;
  27. UCHAR the_IRQ, the_DMA;
  28. BOOL sound_exists;
  29. BOOL mod_playing, music_playing;
  30. BOOL sounds_playing[MAX_CHANNEL-START_CHANNEL];
  31. USHORT sample_count;
  32.  
  33. #ifdef OS_DOS
  34. Module * the_song;
  35. Sample * samples[MAX_SAMPLES];
  36. #endif
  37.  
  38. void Init_Sound() {
  39. #ifdef OS_DOS
  40. FILE * fp;
  41. short temp_1, temp_2, temp_3;
  42.  
  43. fp=fopen("sound.cfg", "r+t");
  44. if (fp==NULL) {
  45.    fclose(fp);
  46.    system("sndcfg.exe");
  47.    fopen("sound.cfg", "r+t");
  48.    }
  49. fscanf(fp, "%hd\n", &temp_1);
  50. sound_exists=(temp_1>0 ? TRUE : FALSE);
  51. if (sound_exists) {
  52.    fscanf(fp, "%hd\n%hd\n%hd\n", &temp_1, &temp_2, &temp_3);
  53.    the_port=temp_1;
  54.    the_IRQ=temp_2;
  55.    the_DMA=temp_3;
  56. }
  57. fclose(fp);
  58. mod_playing=FALSE;
  59. music_playing=FALSE;
  60. the_song=NULL;
  61. MODPlayModule(NULL, DEF_CHANS, KHZ_22, the_port, the_IRQ, the_DMA, PM_MANUAL);
  62. sample_count=0;
  63. #endif
  64. }
  65.  
  66. void Play_Song(PCHAR filename) {
  67. if (sound_exists) {
  68. #ifdef OS_DOS
  69.       if (music_playing) {
  70.          MODStopModule();
  71.       }
  72.       if (mod_playing) {
  73.          MODFreeModule(the_song);
  74.       }
  75.       the_song=MODLoadModule(filename);
  76.       if (music_playing) {
  77.          MODPlayModule(the_song, DEF_CHANS, KHZ_22, the_port, the_IRQ, the_DMA, PM_MANUAL);
  78.       }
  79.       mod_playing=TRUE;
  80. #endif
  81. }
  82. }
  83.  
  84. void Start_Music() {
  85. if (sound_exists) {
  86. #ifdef OS_DOS
  87.    MODStopModule();
  88.    MODPlayModule(the_song, DEF_CHANS, KHZ_22, the_port, the_IRQ, the_DMA, PM_MANUAL);
  89.    music_playing=TRUE;
  90. #endif
  91. }
  92. }
  93.  
  94. void Stop_Music() {
  95. if (sound_exists) {
  96. #ifdef OS_DOS
  97.    MODStopModule();
  98.    MODPlayModule(NULL, DEF_CHANS, KHZ_22, the_port, the_IRQ, the_DMA, PM_MANUAL);
  99.    music_playing=FALSE;
  100. #endif
  101. }
  102. }
  103.  
  104. long Load_Sound(PCHAR filename) {
  105. if (sound_exists) {
  106. #ifdef OS_DOS
  107.    if (sample_count<MAX_SAMPLES)
  108.       samples[sample_count++]=MODLoadSample(filename);
  109.    else return -1;
  110. #endif
  111. }
  112. return (sample_count-1);
  113. }
  114.  
  115. void Play_Sound(long id) {
  116. if (id==-1)
  117.   return;
  118. if (sound_exists) {
  119. #ifdef OS_DOS
  120.    MODPlaySample(cur_channel, samples[id]);
  121.    if ((++cur_channel)>=MAX_CHANNEL)
  122.       cur_channel=START_CHANNEL;
  123. #endif
  124. }
  125.  
  126. }
  127.  
  128. void Update_Sound() {
  129. #ifdef OS_DOS
  130. if (sound_exists)
  131.    MODPoll();
  132. #endif
  133. }
  134.  
  135. void Close_Sound() {
  136.    if (sound_exists) {
  137. #ifdef OS_DOS
  138.       MODStopModule();
  139.       if (mod_playing) {
  140.          MODFreeModule(the_song);
  141.       }
  142. #endif
  143.    }
  144. }
  145.